#pragma comment(lib, "glew32.lib")
#pragma comment(lib, "glfwdll_d.lib")
#pragma comment(lib, "opengl32.lib")

#include <gl\glew.h>
#include <gl\glfw.h>
#include <cstdio>
#include <string>
#include "gl_hershey.h"


void doUI()
{
	int mousx,mousy;
	glfwGetMousePos( &mousx, &mousy );

	glLineWidth(1.5f);
	HersheyText::Instance()->setFont(16,24);
	HersheyText::Instance()->moveTo(20,20);
	HersheyText::Instance()->glPrintf("Hei ... skulle gjerne hatt en skikkelig font!");

	std::string big_str = "Nor again is there anyone who loves or pursues or desires to\n"
		"obtain pain of itself, because it is pain, \n"
		"but occasionally circumstances occur in which toil\n"
		"and pain can procure him some great pleasure. \n"
		"To take a trivial example, which of us ever \n"
		"undertakes laborious physical exercise,\n"
		"except to obtain some advantage from it?\n"
		"But who has any right to find fault with \n"
		"a man who chooses to enjoy a pleasure that has no annoying consequences,\n"
		"or one who avoids a pain that produces no resultant pleasure?\n";

	big_str += "\n";
	big_str += "lorem ipsum, quia dolor sit amet, consectetur, adipisci[ng] velit, sed quia non numquam [do] \n"
		       "eius modi tempora inci[di]dunt, ut labore et dolore magnam aliquam quaerat voluptatem. \n"
			   "Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam,\n"
			   "nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, \n"
			   "qui in ea voluptate velit esse, quam nihil molestiae consequatur,\n"
			   "vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?\n";

	big_str += "\n";
	big_str += "lorem ipsum, quia dolor sit amet, consectetur, adipisci[ng] velit, sed quia non numquam [do] \n"
		"eius modi tempora inci[di]dunt, ut labore et dolore magnam aliquam quaerat voluptatem. \n"
		"Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam,\n"
		"nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, \n"
		"qui in ea voluptate velit esse, quam nihil molestiae consequatur,\n"
		"vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?\n";

	HersheyText::Instance()->setFont(8,12);
	HersheyText::Instance()->moveTo(10,40);
	glLineWidth(0.85f);
	HersheyText::Instance()->glPrintf( big_str.c_str() );
}

int main(char **argv,int argc )
{
	glfwInit();
	int xres=640;
	int yres=480;
	glfwOpenWindow(xres,yres,0,0,0,0,0,0,GLFW_WINDOW);
	if (glewInit() != GLEW_OK)
	{
		printf("GLEW initialization failed\n");
		return 0;
	}
	glfwSwapInterval(0);

	glEnable(GL_DEPTH_TEST);
	glClearColor(0, 0, 0, 1);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,xres,yres,0,-1,1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
#define ANTI_ALIAS
#ifdef ANTI_ALIAS
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_LINE_SMOOTH);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glDepthFunc(GL_ALWAYS);
#endif

	double dt = 0.0;
	double oldtime = glfwGetTime();
	
	bool running = true;
	while( running )
	{
		double time = glfwGetTime();
		dt = time - oldtime;
		oldtime = time;
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		doUI();
		glfwSwapBuffers();

		if( glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED)){
			running = false;
		}

		char buf[64];
		sprintf_s(buf,64,"mspf: %.2f", dt*1000.0);
		glfwSetWindowTitle(buf);
	}

	glfwTerminate();
	return 0;
}